/*
 * @Date         : 2024-05-11 23:15:37 星期6
 * @Author       : xut
 * @Description  : grpc server 和 client 复用的 proto 文件加载逻辑
 */
import { resolve } from "node:path"
import grpc from "@grpc/grpc-js"
import protoLoader from "@grpc/proto-loader"

const PROTO_PATH = resolve(process.cwd(), "./helloworld.proto")

const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
})

const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
const helloProto = protoDescriptor.helloworld // helloworld 为 proto 中 package 字段定义的包名

export default helloProto
